<html>

	<head>
		<meta charset="UTF-8">
		<title>新建设备台账</title>
		<meta name="renderer" content="webkit">
		<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
		<link rel="stylesheet" href="../../layui/css/layui.css" />
		<link rel="stylesheet" href="../../css/bass.css" />
		<link rel="stylesheet" href="../../css/city-picker.css" />
		<style type="text/css">
			.layui-input-block {
				margin-left: 78px;
			}
			
			.city-picker-dropdown {
				left: -148px !important;
			}
		</style>
	</head>

	<body>
		<div class="body">
			<header class="layui-nav" id="headerTop"></header>
			<div class="left_muen" id="left_menu"></div>
			<div class="content_body">
				<!--标题栏-->
				<p class="content_title">设备台账管理&nbsp;&nbsp;>&nbsp;&nbsp;设备台账列表 &nbsp;&nbsp;>&nbsp;&nbsp;修改设备台账</p>
				<!--标题栏-->
				<form class="layui-form mt20">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">设备名称</label>

							<div class="layui-input-inline">
								<input type="text" name="jiqiname" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">设备编号</label>

							<div class="layui-input-inline">
								<input type="text" name="jiqicode" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">设备分类</label>

							<div class="layui-input-inline">
								<select name="jiqimodules" lay-verify="required" lay-search="">
									<option value="涡轮流量计">涡轮流量计</option>
									<option value="超声波流量计">超声波流量计</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">设备状态&nbsp;&nbsp;</label>

							<div class="layui-input-inline">
								<select name="jiqistatus" lay-verify="required" lay-search="">
									<option value="0">使用中</option>
									<option value="1">禁用</option>
									<option value="2">告警</option>
									<option value="3">离线</option>
								</select>
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">设备类型</label>

							<div class="layui-input-inline">
								<select name="jiqiclassfi" lay-verify="required" lay-search="">
									<option value="空">空</option>
									<option value="计量仪器">计量仪器</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">设备条码</label>

							<div class="layui-input-inline">
								<input type="text" name="jiqiercode" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">安装地点</label>

							<div class="layui-input-inline">
								<select name="jiqiposi" lay-verify="required" lay-search="">
									<option value="门站">门站</option>
									<option value="调压站">调压站</option>
									<option value="LNG站">LNG站</option>
									<option value="电厂">电厂</option>
									<option value="直供用户">直供用户</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">安装位置&nbsp;&nbsp;</label>

							<div class="layui-input-inline">
								<!--<input type="text" name="jiqiaddress" autocomplete="off" class="layui-input">-->
								<input disabled="disabled" type="text" lay-verify="required" name="jiqiaddress" class="layui-input" id="target" data-toggle="city-picker" value="江苏省/常州市/溧阳市">
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">设备型号</label>

							<div class="layui-input-inline">
								<input type="text" name="jiqixinghao" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">设备规格</label>

							<div class="layui-input-inline">
								<input type="text" name="jiqiguige" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">设备位号</label>

							<div class="layui-input-inline">
								<input type="text" name="jiqiweihao" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label" style="padding-right: 10px">设备父位号</label>

							<div class="layui-input-inline">
								<input type="text" name="jiqifuweihao" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">供应商&nbsp;&nbsp;&nbsp;&nbsp;</label>

							<div class="layui-input-inline">
								<select name="jiqishanghu" lay-verify="required" lay-search="" id="deviceParentPositionNum">
									<option value="">请选择</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">设备厂商</label>

							<div class="layui-input-inline">
								<select name="jiqichangshang" lay-verify="required" lay-search="" id="deviceProducer">
									<option value="">请选择</option>
								</select>
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">到货时间</label>

							<div class="layui-input-block">
								<input type="text" name="daohuoshijian" id="date1" lay-verify="date" placeholder="请选择时间" autocomplete="off" class="layui-input" style="width: 93%">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">使用时间</label>

							<div class="layui-input-block">
								<input type="text" name="shiyongshijian" id="date2" lay-verify="date" placeholder="请选择时间" autocomplete="off" class="layui-input" style="width: 96%">
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">报废时间</label>

							<div class="layui-input-block">
								<input type="text" name="baofeishijian" id="date3" lay-verify="date" placeholder="请选择时间" autocomplete="off" class="layui-input" style="width: 95%">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">设备用途</label>

							<div class="layui-input-inline">
								<input type="text" name="jiqiyongtu" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">出厂编号</label>

							<div class="layui-input-inline">
								<input type="text" name="chuchangbiaohao" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">出厂日期</label>

							<div class="layui-input-block">
								<input type="text" name="chuchangriqi" id="date4" lay-verify="date" placeholder="请选择时间" autocomplete="off" class="layui-input" style="width: 97%">
							</div>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">责任部门</label>

							<div class="layui-input-inline">
								<input type="text" name="zerenbumen" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">&nbsp;&nbsp;负责人&nbsp;&nbsp;</label>

							<div class="layui-input-inline">
								<input type="text" name="fuzeren" lay-verify="required" autocomplete="off" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<label class="layui-form-label">购置价值</label>
							<div class="layui-input-inline">
								<input type="text" name="gouzhijiazhi" lay-verify="required|number" autocomplete="off" class="layui-input">
							</div>
							<label class="layui-form-label" style="padding-left: 2px">(元)</label>
						</div>
					</div>
					<div class="layui-form-item layui-form-text">
						<label class="layui-form-label">备注</label>
						<div class="layui-input-block" style="width: 90%">
							<textarea placeholder="请输入内容" class="layui-textarea" id="lay_beizhu"></textarea>
						</div>
					</div>
					<div class="layui-form-item">
						<div class="layui-input-block">
							<div class="layui-btn" lay-submit="" lay-filter="submitFilter">立即提交</div>
							<button type="reset" class="layui-btn layui-btn-primary">重置</button>
						</div>
					</div>
				</form>
			</div>
		</div>
		<script src="../../js/common/jquery-1.11.3.min.js"></script>
		<script src="../../layui/layui.js"></script>
		<script src="../../js/common/navList.js"></script>
		<script src="../../js/common/ajax.js"></script>
		<script src="../../js/city-picker.data.js"></script>
		<script src="../../js/city-picker.js"></script>
		<script src="../../js/main.js"></script>
		<script>
			var href = window.location.href;
			var id = href.split("?")[1].split("&")[2] ? href.split("?")[1].split("&")[2].split("=")[1] : "";
			$('#target').citypicker();
			layui.use(['form', 'layedit', 'laydate'], function() {
				var form = layui.form,
					layer = layui.layer,
					layedit = layui.layedit,
					laydate = layui.laydate;
				//              初始化供应商和设备厂商

				ajaxGet({
					url: 'manufacturer/getListAll',
					async: true,
					data: {
						maType: 1, //1供应商2设备厂商
					},
					successFull: function(res) {
						console.log(res);

						$.each(res, function(i, item) {
							$("#deviceParentPositionNum").append('<option value="' + item.maAllTitle + '">' + item.maAllTitle + '</option>');
						});
						layui.form.render('select'); //重新渲染select
					},
					errCallBack: function(res) {
						$.each(res, function(i, item) {
							$("#deviceParentPositionNum").append('<option value="' + item.maAllTitle + '">' + item.maAllTitle + '</option>');
						});
						layui.form.render('select'); //重新渲染select
					}
				});
				ajaxGet({
					url: 'manufacturer/getListAll',
					async: true,
					data: {
						maType: 2, //1供应商2设备厂商
					},
					successFull: function(res) {
						console.log(res);
						$.each(res, function(i, item) {
							$("#deviceProducer").append('<option value="' + item.maAllTitle + '">' + item.maAllTitle + '</option>');
						});
						layui.form.render('select'); //重新渲染select
					},
					errCallBack: function(res) {
						console.log(res);
						$.each(res, function(i, item) {
							$("#deviceProducer").append('<option value="' + item.maAllTitle + '">' + item.maAllTitle + '</option>');
						});
						layui.form.render('select'); //重新渲染select
					}

				})
				//合同签订时间
				laydate.render({
					elem: '#date'
				});
				//合同有效时间
				laydate.render({
					elem: '#date1'
				});
				//合同有效时间:
				laydate.render({
					elem: '#date2'
				});
				laydate.render({
					elem: '#date3'
				});
				laydate.render({
					elem: '#date4'
				});
				if(id) {
					//初始化页面值
					$.ajax({
						url: baseUrl + "/ledger/getById?id=" + id,
						type: "GET",
						dataType: "json",
						success: function(data) {
							console.log(data);
							$("[name = jiqiname]").val(data.deviceName);
							$("[name = jiqicode]").val(data.deviceCode);
							$("[name = jiqiclassfi]").val(data.deviceType);
							$("[name = jiqistatus]").val(data.deviceStatus);
							$("[name = jiqimodules]").val(data.deviceClass);
							$("[name = jiqiercode]").val(data.deviceBarCode);
							$("[name = jiqiposi]").val(data.deviceInstallAddress);
//							$("[name = jiqiaddress]").val(data.deviceInstallPosition);
							$("#target").val(data.deviceInstallPosition);
//							$(".city-picker-span").html(data.deviceInstallPosition);
							$("[name = jiqixinghao]").val(data.deviceModel);
							$("[name = jiqiguige]").val(data.deviceSpec);
							$("[name = jiqiweihao]").val(data.devicePositionNum);
							$("[name = jiqifuweihao]").val(data.deviceParentPositionNum);
							$("[name = jiqishanghu]").val(data.deviceSupplier);
							$("[name = jiqichangshang]").val(data.deviceProducer);
							$("[name = daohuoshijian]").val(data.deviceArrivalDate);
							$("[name = shiyongshijian]").val(data.deviceApplyDate);
							$("[name = baofeishijian]").val(data.deviceScrapDate);
							$("[name = chuchangriqi]").val(data.deviceOutFactoryDate);
							$("[name = jiqiyongtu]").val(data.devicePurpose);
							$("[name = chuchangbiaohao]").val(data.deviceOutFactoryCode);
							$("[name = zerenbumen]").val(data.responsibilityDep);
							$("[name = fuzeren]").val(data.responsibilityUser);
							$("[name = gouzhijiazhi]").val(data.devicePrice);
							$("#lay_beizhu").val(data.deviceDesc);
//							安装地址渲染
							var position = data.deviceInstallPosition.split("/");
							var str = '';
							$.each(position, function(i,item) {
								if(i == 0){
									str+='<span class="select-item" data-count="province" data-code="1">'+item+'</span>'+'/';
								};
								if(i== 1){
									str+='<span class="select-item" data-count="city" data-code="2800">'+item+'</span>'+'/';
								};
								if(position.length == 4){
									if(i==2){
										str+='<span class="select-item" data-count="district" data-code="2849">'+item+'</span>'+'/';
									};
									if(i==3){
										str+='<span class="select-item" data-count="county" data-code="42647">'+item+'</span>'
									}
									
								}else if(position.length == 3){
									if(i==2){
										str+='<span class="select-item" data-count="district" data-code="2849">'+item+'</span>';
									};
								};
							});
							console.log(str);
							$(".city-picker-span span").eq(0).css("display","inline");
							$(".city-picker-span span").eq(0).html(str);
							layui.form.render('select'); //重新渲染select
						}
					});
				}
				//监听提交
				form.on('submit(submitFilter)', function(data) {
					if(data.field.jiqiaddress != '') {
						var address = data.field.jiqiaddress.split("/")[0] + data.field.jiqiaddress.split("/")[2] + data.field.jiqiaddress.split("/")[1];
						var city = data.field.jiqiaddress.split("/")[1]
						$.ajax({
							url: 'http://api.map.baidu.com/geocoder/v2/',
							type: 'GET',
							dataType: "jsonp",
							data: {
								address: address,
								city: city,
								output: 'json',
								ak: 'Dgss6mIeNeCGttMM4llQ3sQGRhGNI8Ai',
								precise: 1
							},
							success: function(res) {
								console.log(res)
								if(res.status == 0) {
									var lng = res.result.location.lng;
									var lat = res.result.location.lat;
									ajaxPost({
										url: 'ledger/update',
										data: {
											id: id,
											deviceCode: data.field.jiqicode, //设备编号
											deviceName: data.field.jiqiname, //设备名称
											deviceType: data.field.jiqiclassfi, //设备类型
											deviceStatus: data.field.jiqistatus, //设备状态 0使用中 1禁用
											deviceClass: data.field.jiqimodules, //设备分类
											deviceBarCode: data.field.jiqiercode, //设备条码
											deviceInstallAddress: data.field.jiqiposi, // 安装地址
											deviceInstallPosition: data.field.jiqiaddress, //安装位置
											deviceModel: data.field.jiqixinghao, //设备型号,
											deviceSpec: data.field.jiqiguige, //设备规格,
											devicePositionNum: data.field.jiqiweihao, //设备位号,
											deviceParentPositionNum: data.field.jiqifuweihao, //设备父位号deviceSupplier;
											deviceSupplier: data.field.jiqishanghu,//供应商
											deviceProducer: data.field.jiqichangshang, //设备厂商
											deviceArrivalDate: data.field.daohuoshijian, //到货时间
											deviceApplyDate: data.field.shiyongshijian, //使用时间
											deviceScrapDate: data.field.baofeishijian, //报废日期
											deviceOutFactoryDate: data.field.chuchangriqi, //出厂日期
											devicePurpose: data.field.jiqiyongtu, //设备用途
											deviceOutFactoryCode: data.field.chuchangbiaohao, //出厂编号
											responsibilityDep: data.field.zerenbumen, //责任部门
											responsibilityUser: data.field.fuzeren, //责任人
											devicePrice: data.field.gouzhijiazhi, //设备价格
											deviceDesc: $("#lay_beizhu").val(), //备注
											deviceLongitude: lng, //经度
											deviceLatitude: lat, //纬度
										},
										successFull: function(res) {
											console.log(res)
											layer.msg('添加成功', {
												icon: 6
											});
											window.location.href = "./accountsList.html?pos=0&childPos=0";
										},
										errCallBack: function(res) {
											layer.msg(res.msg, {
												icon: 6
											});
										}
									});
								} else {
									layer.msg('无效地理位置', {
										icon: 6
									});
								}
							},
							error: function(res) {
								layer.msg('请输入正确的安装位置', {
									icon: 6
								});
							}
						})
					}
					//					console.log(data.field)
					//					ajaxPost({
					//						url: 'ledger/update',
					//						data: {
					//							id: id, //编号
					//							deviceCode: data.field.jiqicode, //设备编号
					//							deviceName: data.field.jiqiname, //设备名称
					//							deviceType: data.field.jiqiclassfi, //设备类型
					//							deviceStatus: data.field.jiqistatus, //设备状态 0使用中 1禁用
					//							deviceClass: data.field.jiqimodules, //设备分类
					//							deviceBarCode: data.field.jiqiercode, //设备条码
					//							deviceInstallAddress: data.field.jiqiposi, // 安装地址
					//							deviceInstallPosition: data.field.jiqiaddress, //安装位置
					//							deviceModel: data.field.jiqixinghao, //设备型号,
					//							deviceSpec: data.field.jiqiguige, //设备规格,
					//							devicePositionNum: data.field.jiqiweihao, //设备位号,
					//							deviceParentPositionNum: data.field.jiqifuweihao, //设备父位号deviceSupplier;供应商
					//							deviceSupplier: data.field.deviceSupplier,
					//							deviceProducer: data.field.jiqichangshang, //设备厂商
					//							deviceArrivalDate: data.field.daohuoshijian, //到货时间
					//							deviceApplyDate: data.field.shiyongshijian, //使用时间
					//							deviceScrapDate: data.field.baofeishijian, //报废日期
					//							deviceOutFactoryDate: data.field.chuchangriqi, //出厂日期
					//							devicePurpose: data.field.jiqiyongtu, //设备用途
					//							deviceOutFactoryCode: data.field.chuchangbiaohao, //出厂编号
					//							responsibilityDep: data.field.zerenbumen, //责任部门
					//							responsibilityUser: data.field.fuzeren, //责任人
					//							devicePrice: data.field.gouzhijiazhi, //设备价格
					//							deviceDesc: $("#lay_beizhu").val(), //备注
					//							deviceLongitude: '', //经度
					//							deviceLatitude: '', //纬度
					//						},
					//						successFull: function(res) {
					//							console.log(res)
					//							layer.msg('添加成功', {
					//								icon: 6
					//							});
					//							window.location.href = "./accountsList.html?pos=0&childPos=0";
					//						},
					//						errCallBack: function(res) {
					//							layer.msg(res.msg, {
					//								icon: 6
					//							});
					//						}
					//					})
				});
			});
		</script>
	</body>

</html>